package com.venta.autopartes.utils;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

public class SessionFactory {
	private static Map session;
	
	public static Map getSession(){
		if(session==null){
			session = ActionContext.getContext().getSession();
		}
		
		return session;
	}
	
	public static void destroySession(){
		session=null;
	}
	
	public static void deleteUser(){
		if(session.containsKey(RolesUsuario.USERNAME)){
			session.remove(RolesUsuario.USERNAME);
		}
	}
	
	public static void removePreviosSessionData(){
		session=getSession();
		
		/*if (session.get("vehiclesListSearch") != null) {
			session.remove("vehiclesListSearch");
		}*/

		if (session.get(Constants.VEHICLE_SEARCH_RESULT) != null) {
			session.remove(Constants.VEHICLE_SEARCH_RESULT);
		}
		
		if (session.get(Constants.USER_SEARCH_RESULT) != null) {
			session.remove(Constants.USER_SEARCH_RESULT);
		}
		
		if (session.get(Constants.BRANCH_SEARCH_RESULT) != null) {
			session.remove(Constants.BRANCH_SEARCH_RESULT);
		}
		
		/*
		if (session.get("usersListSearch") != null) {
			session.remove("usersListSearch");
		}*/

	}
	
	public static void removeCountrySelection(){

		if (session.get("selectedCountry") != null) {
			session.remove("selectedCountry");
		}
		
		if (session.get("selectedState") != null) {
			session.remove("selectedState");
		}
		
		if (session.get("selectedTown") != null) {
			session.remove("selectedTown");
		}
		if (session.get("selectedSuburb") != null) {
			session.remove("selectedSuburb");
		}
	}

}
